home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / mapclassiclayout.py < prev    next >
Text File  |  2004-01-05  |  6KB  |  239 lines

  1. """   QuArK  -  Quake Army Knife
  2.  
  3. Plug-in which define the Classical screen layout.
  4. """
  5. #
  6. # Copyright (C) 1996-99 Armin Rigo
  7. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  8. # FOUND IN FILE "COPYING.TXT"
  9. #
  10.  
  11. #$Header: /cvsroot/quark/runtime/plugins/mapclassiclayout.py,v 1.2 2000/06/03 10:25:30 alexander Exp $
  12.  
  13.  
  14.  
  15. Info = {
  16.    "plug-in":       "Classic Layout",
  17.    "desc":          "QuArK's classic 2-views Screen Layout.",
  18.    "date":          "31 oct 98",
  19.    "author":        "Armin Rigo",
  20.    "author e-mail": "arigo@planetquake.com",
  21.    "quark":         "Version 5.1" }
  22.  
  23.  
  24. from quarkpy.mapmgr import *
  25.  
  26.  
  27. #
  28. # The Classic Layout is implemented as a subclass of the base class MapLayout.
  29. #
  30.  
  31. class ClassicLayout(MapLayout):
  32.     "The classic 2-views QuArK layout."
  33.  
  34.     shortname = "Classic"
  35.  
  36.     def buildscreen(self, form):
  37.  
  38.         #
  39.         # We put the standard left panel first.
  40.         #
  41.  
  42.         self.bs_leftpanel(form)
  43.  
  44.         #
  45.         # Divide the main panel into two sections.
  46.         # horizontally, 1 section;
  47.         # vertically, 2 sections split at 40% of the height
  48.         #  (use "-0.4" instead of "0.4" to disable user resizing)
  49.         #
  50.  
  51.         form.mainpanel.sections = ((), (0.4,))
  52.  
  53.         #
  54.         # Create the XY view in the section (0,1), i.e. down.
  55.         #
  56.  
  57.         self.ViewXY = form.mainpanel.newmapview()
  58.         self.ViewXY.section = (0,1)
  59.  
  60.         #
  61.         # Create the XZ view in the section (0,0) (it is there by default).
  62.         #
  63.  
  64.         self.ViewXZ = form.mainpanel.newmapview()
  65.  
  66.         #
  67.         # Put these two views in the view lists.
  68.         #
  69.  
  70.         self.views[:] = [self.ViewXY, self.ViewXZ]
  71.         self.baseviews = self.views[:]
  72.  
  73.         #
  74.         # Setup initial display parameters.
  75.         #
  76.  
  77.         scale = 0.25   # default value
  78.  
  79.         self.ViewXY.info = {
  80.           "type": "XY",     # XY view
  81.           "angle": 0.0,     # compass angle
  82.           "scale": scale,   # scale
  83.           "vangle": 0.0}    # vertical angle
  84.  
  85.         self.ViewXZ.info = {
  86.           "type": "XZ",     # XZ view
  87.           "angle": 0.0,
  88.           "scale": scale,
  89.           "vangle": 0.0}
  90.  
  91.         #
  92.         # Link the horizontal position of the XZ view to that of the
  93.         # XY view, and remove the horizontal scroll bar of the XZ view.
  94.         #
  95.  
  96.         self.sblinks.append((0, self.ViewXY, 0, self.ViewXZ))
  97.         self.ViewXZ.flags = self.ViewXZ.flags &~ MV_HSCROLLBAR
  98.  
  99.  
  100.     #
  101.     # The following function is called when the configuration changed.
  102.     # We show or hide the red lines here.
  103.     #
  104.  
  105.     def setupchanged(self, level):
  106.  
  107.         #
  108.         # First call the inherited "setupchanged".
  109.         #
  110.  
  111.         MapLayout.setupchanged(self, level)
  112.  
  113.  
  114.         #
  115.         # Read the old flags and set both red lines by default.
  116.         #
  117.  
  118.         flagsXY = self.ViewXY.flags | MV_TOPREDLINE | MV_BOTTOMREDLINE
  119.         flagsXZ = self.ViewXZ.flags | MV_TOPREDLINE | MV_BOTTOMREDLINE
  120.  
  121.         #
  122.         # Remove the 2nd red line if required.
  123.         #
  124.  
  125.         if not MapOption("RedLines2"):
  126.             flagsXY = flagsXY &~ MV_TOPREDLINE
  127.             flagsXZ = flagsXZ &~ MV_BOTTOMREDLINE
  128.  
  129.         #
  130.         # Update the flags.
  131.         #
  132.  
  133.         self.ViewXY.flags = flagsXY
  134.         self.ViewXZ.flags = flagsXZ
  135.  
  136.  
  137.  
  138.     #
  139.     # The following function is called to compute the limits of
  140.     # the visible (non-grayed-out) areas for each map view.
  141.     #
  142.  
  143.     def setupdepth(self, view):
  144.  
  145.         #
  146.         # First check the "view" parameter.
  147.         #
  148.  
  149.         if (view is not self.ViewXY) and (view is not self.ViewXZ):
  150.             return
  151.  
  152.         #
  153.         # To compute the visible areas for the XY view, we
  154.         # get the rectangular area (in pixels) of the XZ view.
  155.         #
  156.  
  157.         x1,y1,x2,y2 = self.ViewXZ.redlinesrect
  158.  
  159.         #
  160.         # The line below does this :
  161.         #  * take a corner of the above rectangle
  162.         #  * compute the 3D coordinates of any point above this corner
  163.         # This gives a 3D point that is at the top limit of the visible area for the XY view.
  164.         #  * project this 3D point on the XY view
  165.         #  * keep only the z coordinate (i.e. the depth) of this projection
  166.         # This gives the depth of the top limit, which is what we wanted.
  167.         #
  168.         # The second line does the same for the other corner, which gives
  169.         # the bottom limit of the visible area.
  170.         #
  171.  
  172.         xydepth = (self.ViewXY.proj(self.ViewXZ.space(x1, y1, 0.0)).z,
  173.                    self.ViewXY.proj(self.ViewXZ.space(x2, y2, 0.0)).z)
  174.  
  175.         #
  176.         # Do it again for the XZ view...
  177.         #
  178.  
  179.         x1,y1,x2,y2 = self.ViewXY.redlinesrect
  180.         xzdepth = (self.ViewXZ.proj(self.ViewXY.space(x2, y2, 0.0)).z,
  181.                    self.ViewXZ.proj(self.ViewXY.space(x1, y1, 0.0)).z)
  182.  
  183.         #
  184.         # Depending on the draw mode, items may or may not be grayed
  185.         # out. If they are, we must redraw a view when the other one
  186.         # is scrolled, in case objects came in or out of view. This
  187.         # is done by calling "setdepth". Otherwise, we directly set
  188.         # the map view's "depth" attribute, which doesn't redraw the
  189.         # view.
  190.         #
  191.  
  192.         redraw = self.editor.drawmode & DM_MASKOOV
  193.  
  194.         if redraw and (view is not self.ViewXY):
  195.             self.ViewXY.setdepth(xydepth)
  196.         else:
  197.             self.ViewXY.depth = xydepth
  198.  
  199.         if redraw and (view is not self.ViewXZ):
  200.             self.ViewXZ.setdepth(xzdepth)
  201.         else:
  202.             self.ViewXZ.depth = xzdepth
  203.  
  204.  
  205.     #
  206.     # Functions to read and store the layout (window positions,...)
  207.     # in the Setup.
  208.     #
  209.  
  210.     def readconfig(self, config):
  211.         MapLayout.readconfig(self, config)
  212.         vsec = config["vsec"]
  213.         if type(vsec)==type(()) and len(vsec)==1:
  214.             self.editor.form.mainpanel.sections = ((), vsec)
  215.  
  216.     def writeconfig(self, config):
  217.         MapLayout.writeconfig(self, config)
  218.         hsec, vsec = self.editor.form.mainpanel.sections
  219.         config["vsec"] = vsec
  220.  
  221.  
  222.  
  223. #
  224. # Register the new layout. (this one is the default one, so add it at the front of the list)
  225. #
  226.  
  227. LayoutsList.insert(0, ClassicLayout)
  228.  
  229.  
  230. # ----------- REVISION HISTORY ------------
  231. #
  232. #
  233. # $Log: mapclassiclayout.py,v $
  234. # Revision 1.2  2000/06/03 10:25:30  alexander
  235. # added cvs headers
  236. #
  237. #
  238. #
  239. #